<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/icons-extra.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/base.css">
		<style>
			/* 当前页面内部样式 */
		.menu{
			display: flex;
			flex-wrap: nowrap;
			/* 左右分布，容器两边带有间隙 */
			justify-content: space-around;
			margin-top: .24rem;
		}
		.menu .item{
			width: 46%;
			height: 3rem;
			line-height: 3rem;
			color: #fff;
			text-align: center;
			border-radius: .1rem;
		}
		.menu .item:first-child{
			background: linear-gradient(90deg, #941AE6, #F1E0FC); 
			background: -webkit-gradient(90deg, #941AE6, #F1E0FC);
		}
		.menu .item:last-child{
			background: linear-gradient(#3370CC, #CEE1FD); 
			background: -webkit-gradient(#3370CC, #CEE1FD);
		}
		.db-movie-list:before{
			display: none;
		}
		
		.title{
			font-size: .36rem;
			text-indent: .2rem;
			position: relative;
			line-height: .8rem;
		}
		.title::after{
			content: '';
			display: block;
			position: absolute;
			width: 100%;
			height: 1px;
			background-color: #b6b5b8;
		}
		
		.db-movie-list{
			margin-bottom: 1rem;
		}
		.db-movie-list .mui-media-object{
			max-width: 1.4rem;
			width: 1.4rem;
			height: auto;
		}
		.db-movie-list .mui-media-body{
			font-size: .38rem;
			line-height: .5rem;
		}
		.db-movie-list .mui-media-body .mui-ellipsis span{
			color: #ff6464;
		}
		
		/* 想看 */
		.mui-media{
			position: relative;
		}
		.mui-media .want{
			width: .8rem;
			height: .6rem;
			line-height: .6rem;
			text-align: center;
			position: absolute;
			right: 10px;
			top: 50%;
			transform: translateY(-50%);
			border: 1px solid #FAAA3C;
			color:#FAAA3C;
			font-size: 12px;
		}
	</style>
	</head>
	<body>
		<!-- 头部标题 -->
		<header class="mui-bar mui-bar-nav">
			<!-- <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> -->
			<h1 class="mui-title">榜单</h1>
		</header>

		<!-- 内容主容器 -->
		<div class="mui-content">

			<!-- 轮播图 -->
			<div id="slider" class="mui-slider">
				<div class="mui-slider-group mui-slider-loop">
					<!-- 额外增加的一个节点(循环轮播：第一个节点是最后一张轮播) -->
					<div class="mui-slider-item mui-slider-item-duplicate">
						<a href="#">
							<img src="../images/banner3.jpg">
						</a>
					</div>
					<!-- 第一张 -->
					<div class="mui-slider-item">
						<a href="#">
							<img src="../images/banner1.jpg">
						</a>
					</div>
					<!-- 第二张 -->
					<div class="mui-slider-item">
						<a href="#">
							<img src="../images/banner2.jpg">
						</a>
					</div>
					<!-- 第三张 -->
					<div class="mui-slider-item">
						<a href="#">
							<img src="../images/banner3.jpg">
						</a>
					</div>
					<!-- 额外增加的一个节点(循环轮播：最后一个节点是第一张轮播) -->
					<div class="mui-slider-item mui-slider-item-duplicate">
						<a href="#">
							<img src="../images/banner1.jpg">
						</a>
					</div>
				</div>
				<div class="mui-slider-indicator">
					<div class="mui-indicator mui-active"></div>
					<div class="mui-indicator"></div>
					<div class="mui-indicator"></div>
				</div>
			</div>

			<div id="app">
				<!-- 两个菜单 -->
				<div class="menu">
					<div class="item" @tap="topTap">豆瓣Top250</div>
					<div class="item">北美票房榜</div>
				</div>

				<!-- 标题 -->
				<h3 class="title">即将上映</h3>

				<!-- 图文电影列表 -->


				<!--数据列表-->
				<ul class="mui-table-view mui-table-view-chevron db-movie-list">
					<li class="mui-table-view-cell mui-media" v-for="item in movies" v:key="item.id" @tap="tapDetail(item.id)">
						<a href="javascript:;">
							<img class="mui-media-object mui-pull-left" :src="item.images.large">
							<div class="mui-media-body">
								{{item.title}}
								<p class='mui-ellipsis'>{{item.genres}} <span>暂无评分</span></p>
								<p class='mui-ellipsis'>导演：{{item.directors[0].name}}</p>
								<p class='mui-ellipsis'>主演：{{item.actors}}</p>
							</div>
							<div class="want">想看</div>
						</a>
					</li>

				</ul>
			</div>

		</div>


		<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			let top250;
			let moviesDetail;
			mui.plusReady(function() {
			
				top250 = plus.webview.getWebviewById("top250"); //详细页的窗口对象
				if (!top250) {
					console.log(1);
					// 预加载页面
					top250 = mui.preload({ //预加载自动创建了窗口，加载了文件
						url: '../pages/top250.html',
						id: "top250" //这个也是webview的id
			
					})
				}
				// 电影详情页
				moviesDetail = plus.webview.getWebviewById("moviesDetail"); //详细页的窗口对象
				if (!moviesDetail) {
					console.log(2);
					// 预加载页面
					moviesDetail = mui.preload({ //预加载自动创建了窗口，加载了文件
						url: '../pages/movieDetail.html',
						id: "moviesDetail" //这个也是webview的id
							
					})
				}
			})
			
			let slider = mui('#slider');
			// 设置自动轮播
			slider.slider({
				interval: 3000
			});
			let app = new Vue({
				el: "#app",
				data: {
					movies: []
				},
				methods:{
					
					topTap(){
						mui.openWindow({
							id:"top250"
						})
					},
					tapDetail(id){
						mui.fire(moviesDetail,"getMovie",{
							mid:id
						})
						mui.openWindow({
							id:"moviesDetail"
						})
					}
				}
			})

			mui.getJSON('http://t.yushu.im/v2/movie/coming_soon', {
				start: 0, // 起始记录的下标，第1页第1条记录是 0
				count: 10, // 每页显示的条数
				city: '广州',
				apikey: '0df993c66c0c636e29ecbb5344252a4a'
			}, function(data) { //json对象
				//服务器返回响应，根据响应结果，分析是否登录成功；
				// console.log(JSON.stringify(data)); // 输出json字符串进行调试
				let total = data.total;
				let subjects = data.subjects;
				if (subjects.length > 0) {
					subjects.forEach((v) => {
						// 对电影类型genres进行操作，转成 / 拼接
						v.genres = v.genres.join("/")
						// console.log(v.genres);
						let arr = [];
						// 抽离出主演
						v.casts.forEach((item) => {
							arr.push(item.name)
						})
						v.actors = arr.join('/');
						// console.log(v.actors);
					})
					// 赋值
					app.movies = app.movies.concat(subjects);
				}
			}, function(xhr, type, errorThrown) {
				//异常处理；
				console.log(type);
			});
		</script>
	</body>
</html>
